//导入模块
const express = require('express');
const res = require('express/lib/response');
const db = require('../uilit/mysql')


//创建路由
const myRouter = express.Router();

//接口编写
myRouter.post('/submit', (req, res) => {
  const sql = `UPDATE seeker SET s_password='${req.body.password}' WHERE s_tel='${req.body.telphone}'`
  db.query(sql, (err, data) => {
    if (err) {
      console.log(err)
    } else {
      res.send({ code: '200', msg: '修改成功' })
    }
  })
})


//
myRouter.post('/search',(req,res)=>{
  //job表
  // const sql=` SELECT * FROM job ORDER BY j_date DESC LIMIT 0,6;`;
//公司表
const sql=`SELECT * FROM ( SELECT * FROM job ORDER BY j_date DESC LIMIT 0,9)  AS t2 JOIN company ON t2.c_id=company.c_id  ORDER BY j_date DESC;`;

  db.query(sql,(err,data)=>{
    if(err){
      console.log(err)
    }else{
      res.send({msg:'查询成功',data:data})
    }
  })

})

//更多1
myRouter.post('/more',(req,res)=>{
  const sql2=`SELECT * FROM ( SELECT * FROM job ORDER BY j_date DESC LIMIT 0,9)  AS t1 JOIN job_category ON t1.job_id=job_category.job_id JOIN company ON t1.c_id=company.c_id ORDER BY j_date DESC;`;

  db.query(sql2,(err2,data2)=>{
    if(err2){
      console.log(err2)
    }else{
      res.send({msg:'查询成功',data2:data2})
    }
  })
})

//更多2

myRouter.post('/most',(req,res)=>{
  const sql5=`SELECT * FROM (
    SELECT  job.* ,COUNT(*) FROM job  JOIN  record ON job.j_id=record.j_id GROUP BY job_name ORDER BY COUNT(*) DESC 
    )AS t5 JOIN company ON t5.c_id=company.c_id LIMIT 0,9;`;

  db.query(sql5,(err5,data5)=>{
    if(err5){
      console.log(err5)
    }else{
      res.send({msg:'查询成功',data5:data5})
    }
  })
})




//热门职业

myRouter.post('/career',(req,res)=>{

  const sql4=`SELECT * FROM (
    SELECT  job.* ,COUNT(*) FROM job  JOIN  record ON job.j_id=record.j_id GROUP BY job_name ORDER BY COUNT(*) DESC 
    )AS t5 JOIN company ON t5.c_id=company.c_id LIMIT 0,6;`;
 
    db.query(sql4,(err4,data4)=>{
      if(err4){
        console.log(err4)
    }else{
      res.send({msg:'查询成功',data4:data4})
    }

})

})


















//导出
module.exports = myRouter;